package com.pb.wkflow.core.service;

import com.alibaba.fastjson.JSON;
import com.pb.wkflow.core.entity.PostInfo;
import com.pb.wkflow.core.utils.RestTemplateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 外部接口请求
 * @author 苗益辉
 * @date 2022/5/17 13:45
 */
@Slf4j
@Service
public class IHttpParticipantService {

    public List<PostInfo> execute(String serviceUrl, Map<String, Object> params) {
        if(null == params) {
            params = new HashMap<>(1);
        }
        String stringJson = JSON.toJSONString(params);
        log.info("请求地址：{}， 请求参数：{}",serviceUrl, stringJson);
        String result = RestTemplateUtil.post(serviceUrl, stringJson);
        return JSON.parseArray(result, PostInfo.class);
    }
}